package application.model 
{
	import application.ApplicationFacade;
	import application.model.VO.GroupVO;
	import application.model.VO.PhotoVO;
	import org.puremvc.as3.interfaces.IProxy;
	import org.puremvc.as3.patterns.proxy.Proxy;
	/**
	 * 数据代理
	 * @author Ning
	 */
	public class DataProxy extends Proxy implements IProxy
	{
		public static const NAME:String = 'DataProxy';
		
		private var _groupNames:Array;
		
		public function DataProxy() 
		{
			super(NAME, []);
		}
		public function setConfig():void
		{
			//解析图片数据
			var dataXML:XML = AppGlobal.RESOURES_POOL.getXML(AppGlobal.DATA_KEY);
			
			_groupNames = [];

			for (var i:int = 0; i < dataXML.photos.length(); i++ )
			{
				var arr:Array = [];
				var obj:Object = dataXML.photos[i];
				for (var j:int = 0; j < obj.photo.length(); j++ )
				{
					
					var obj1:Object = obj.photo[j];
					var picvo:PhotoVO = new PhotoVO(obj1.@['name'],
					                            obj1.@['url'],
												obj1.@['url1'],
												obj1.@['title'],
												obj1.@['content']);
					arr.push(picvo);
				}
												  
				_groupNames.push(String(dataXML.photos[i].@['name']));
				picData.push(arr);
			}
		}
		public function getPicDataByIndex(index:int):Array
		{
			return picData[index] as Array;
		}
		
		public function getPicDataByGroupName(name:String):Array {
			var index:int = groupNames.indexOf(name);
			return getPicDataByIndex(index);
		}
		
	    public function get groupNames():Array {
			return _groupNames;
		}
		
		private function get picData():Array {
			return data as Array;
		}
	}
}